package com.maxvision.mybatis.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.google.zxing.PlanarYUVLuminanceSource;
import com.maxvision.mybatis.dto.StudentDto;
import com.maxvision.mybatis.service.IStudentService;
import com.maxvision.mybatis.vo.StudentVo;
import com.maxvision.mybatis.vo.UpdateStudentVo;
import org.apache.xmlbeans.impl.xb.xsdschema.LocalSimpleType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 学生管理
 *
 * @author HuangRongFu
 * @date 2022/10/17
 */

@RestController
@RequestMapping("/student")
public class StudentController {
    
    @Autowired
    private IStudentService studentService;
    
    @PostMapping("/add")
    public ResponseEntity addStudent(@Valid @RequestBody StudentVo vo){
        
        return studentService.addStudent(vo);
    }
    
    @PostMapping("/update")
    public ResponseEntity updateStudent(@Valid @RequestBody UpdateStudentVo vo) throws Exception {
        
        return studentService.updateStudent(vo);
    }
    
    @PostMapping("/impImage")
    public ResponseEntity impImage(@RequestParam("images")MultipartFile[] images) throws Exception {

        long start = System.currentTimeMillis();

        ResponseEntity responseEntity = studentService.impImage(images);
        long end = System.currentTimeMillis();
        System.out.println("调用xx耗时: " + (end - start) + "ms");
        return responseEntity;
    }
    
    @GetMapping("/list")
    public ResponseEntity studentList(@RequestParam(value = "pageNum",required = false) Integer pageNum,
                                      @RequestParam(value = "pageSize", required = false) Integer pageSize){

        System.out.println(pageNum);
        System.out.println(pageSize);
        return studentService.selectList(pageNum, pageSize);
    }
    
    @PostMapping("/mapParams")
    public ResponseEntity mapParams(@RequestBody Map<String, Object> map) {

        String one = map.get("one").toString();
        List<StudentDto> list = (List<StudentDto>)map.get("two");

        for (StudentDto studentDto : list) {

            System.out.println(studentDto.getAge());
        }
        System.out.println(one);
        System.out.println(list);
        return null;
    }
    
}
